package com.pro.controller;

import com.google.gson.Gson;
import com.pro.pojo.JsUserFeedback;
import com.pro.pojo.JsonData;
import com.pro.service.JsFeedbackService;
import com.pro.utils.RedisCache;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:JsFeedbackController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/11/12 19:19
 * @Author: XJR
 */
@RestController
@RequestMapping("/Feedback")
public class JsFeedbackController {

    @Autowired
    private JsFeedbackService service;

    @Autowired
    private RedisCache redisCache;

    private Gson gson = new Gson();

    //查询反馈数据
    @RequestMapping("/selectUserFeedBack")
    public JsonData selectUserFeedBack(String feedbackType,String feedbackStatus,Integer limit,Integer page){
        feedbackType = !("").equals(feedbackType) && feedbackType !=null?"%"+feedbackType+"%":"%%";
        feedbackStatus = !("").equals(feedbackStatus) && feedbackStatus !=null?"%"+feedbackStatus+"%":"%%";
        List<JsUserFeedback> jsUserFeedbacks = service.selectUserFeedBack(feedbackType, feedbackStatus,limit,page);
        Integer integer = service.countUserFeedBack(feedbackType, feedbackStatus);
        //redis缓存
        String feedbackSelectUserFeedBack = redisCache.getCacheObject("FeedbackSelectUserFeedBack");
        List list = gson.fromJson(feedbackSelectUserFeedBack, List.class);
        Integer integer1 = redisCache.getCacheObject("FeedbackCountUserFeedBack");
        return list!=null?JsonData.buildSuccess(list,integer1):JsonData.buildError("服务端错误");
    };

    //通过id查看审核详情
    @RequestMapping("/selectUserFeedBackById")
    public JsonData selectUserFeedBackById(Integer feedbackId){
        JsUserFeedback jsUserFeedback = service.selectUserFeedBackById(feedbackId);
        return jsUserFeedback!=null?JsonData.buildSuccess(jsUserFeedback):JsonData.buildError("服务端错误");
    };

    //删除反馈数据
    @RequestMapping("/delUserFeedBack")
    public JsonData delUserFeedBack(Integer feedbackId){
        Boolean aBoolean = service.delUserFeedBack(feedbackId);
        return aBoolean!=false?JsonData.buildSuccess(aBoolean):JsonData.buildError("服务端错误");
    };

    //审核
    @RequestMapping("/updateUserFeedStatu")
    public JsonData updateUserFeedStatus(JsUserFeedback jsUserFeedback){
        Boolean aBoolean = service.updateUserFeedStatus(jsUserFeedback);
        return aBoolean!=false?JsonData.buildSuccess(aBoolean):JsonData.buildError("服务端错误");
    };


    //查询已受理反馈数据
    @RequestMapping("/selectAdoptUserFeedBack")
    public JsonData selectAdoptUserFeedBack(String feedbackType){
        feedbackType = !("").equals(feedbackType) && feedbackType !=null?"%"+feedbackType+"%":"%%";
        List<JsUserFeedback> jsUserFeedbacks = service.selectAdoptUserFeedBack(feedbackType);
        Integer integer = service.countAdoptUserFeedBack(feedbackType);
        return jsUserFeedbacks!=null?JsonData.buildSuccess(jsUserFeedbacks,integer):JsonData.buildError("服务端错误");
    };
}
